#ifndef TRANSFER_H
#define TRANSFER_H
#include <QMainWindow>
#include <QTimer>
#include <QMap>
#include "server.h"
namespace Ui {
	class MainWindow;
}

struct heartbeatinfo{
    int timestamp;
    char ip[16];
    char host[64];
};

class QUdpSocket;

class CTransfer: public QMainWindow
{
	Q_OBJECT
public:
	CTransfer(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
	~CTransfer();

protected slots:
	void openBtnClicked();
	void sendBtnClicked();
    void dataReceived();
    void sendHeart();
    

	void processMsg(int code, QString msg);


private:
    void init();
    void initGB();
    
    void updateHostTable();
    
private:
	Ui::MainWindow *ui;
    QUdpSocket *_revWBudp;
        
    CServer serv;
    QTimer _hbTimer; // heartbeat
    const int multicastPort = 12345;
    const QString multicastIP = "224.0.0.100";
    
    QMap<QString, heartbeatinfo> _mapHosts;
};

#endif
